Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(components): add PopoverButton (@beta) #1529

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

hermanwikner
Copy link
Member

@hermanwikner hermanwikner commented Dec 20, 2024

Description

This pull request introduces a new PopoverButton (@beta), which is a wrapper around the Popover primitive. It handles focus-locking, opening, closing, auto-focus, setting appropriate ARIA attributes, and more. The following PopoverProps are omitted, replaced, or added:

  • content: replaced with renderContent to allow providing values in the render callback (isOpen).
  • open: omitted, as the open state is controlled internally by the PopoverButton.
  • referenceElement: omitted, as the rendered button is always the reference.
  • children: omitted, as the rendered button will be the children.
  • ariaHasPopUp: added to ensure that this value is included in the rendered button for a11y.

Example 1:

<PopoverButton
  ariaHasPopUp="menu"
  renderButton={({isOpen}) => <button>{isOpen ? 'Close' : 'Open'}</button>}
  renderContent={({close}) => (
    <div role="menu">
      <button role="menuitem" onClick={close}>Item 1</button>
      <button role="menuitem" onClick={close}>Item 2</button>
      <button role="menuitem" onClick={close}>Item 3</button>
    </div>
  )}
/>

Example 2:

<PopoverButton
  ariaHasPopUp="true"
  renderButton={({isOpen}) => <button>{isOpen ? 'Close' : 'Open'}</button>}
  renderContent={({close}) => (
    <div>
      <p>Popover content</p>

      <button onClick={close}>Close</button>
    </div>
  )}
/>

Copy link

vercel bot commented Dec 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sanity-ui-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 20, 2024 3:07pm
sanity-ui-workshop ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 20, 2024 3:07pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant